document
    .getElementById('fileInput')
    .addEventListener('change', handleFile, false);

function handleFile(event) {
    const file = event.target.files[0];
    const reader = new FileReader();

    reader.onload = function (e) {
        const data = new Uint8Array(e.target.result);
        const workbook = XLSX.read(data, { type: 'array' });

        // 假设我们只读取第一个工作表
        const firstSheetName = workbook.SheetNames[0];
        const worksheet = workbook.Sheets[firstSheetName];

        // 将工作表内容转换为 JSON
        const json = XLSX.utils.sheet_to_json(worksheet);
        document.getElementById('output').textContent = JSON.stringify(
            json,
            null,
            2
        );
    };

    reader.readAsArrayBuffer(file);
}
